import 'dart:io';

import 'package:dio/dio.dart';
import 'package:sainbainu/common/http/http.dart';

class CommonApi {
  /// 上传文件
  Future<Map<String, dynamic>> upload(
    File file, {
    ProgressCallback? onSendProgress,
    ProgressCallback? onReceiveProgress,
  }) async {
    FormData formData = FormData.fromMap({
      'file': await MultipartFile.fromFile(file.path),
    });
    Response res = await Http.post(
      '/api/common/upload',
      data: formData,
      options: Options(
        sendTimeout: const Duration(seconds: 60 * 5),
        receiveTimeout: const Duration(seconds: 60 * 5),
      ),
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );
    return res.data;
  }

  /// 发送短信验证码
  Future<Map<String, dynamic>> sendSms(Map data) async {
    Response res = await Http.post('/api/login/sendSms', data: data);
    return res.data;
  }

  /// 获取地区列表
  Future<Map<String, dynamic>> areaList(Map<String, dynamic> params) async {
    Response res = await Http.get('/api/address/area_list', params: params);
    return res.data;
  }

  /// 删除文件
  Future<Map<String, dynamic>> delFile(Map<String, dynamic> data) async {
    Response res = await Http.post('/api/common/delete', data: data);
    return res.data;
  }

  /// 删除搜索历史
  Future<Map<String, dynamic>> clearSearchHistory() async {
    Response res = await Http.post('/api/customer_search/search_clear');
    return res.data;
  }

  /// 获取搜索历史
  Future<Map<String, dynamic>> searchHistory() async {
    Response res = await Http.get('/api/customer_search/search_history');
    return res.data;
  }

  /// 获取热门搜索
  Future<Map<String, dynamic>> searchHot() async {
    Response res = await Http.get('/api/customer_search/search_hot');
    return res.data;
  }

  /// 搜索
  Future<Map<String, dynamic>> search(Map data) async {
    Response res = await Http.post(
      '/api/customer_search/search',
      data: data,
    );
    return res.data;
  }

  /// 获取 oss -> sts
  Future<Map<String, dynamic>> getAuthSts() async {
    Response res = await Http.get('/api/common/sts');
    return res.data;
  }
}
